import { defineStore } from 'pinia'
import { getStorage, setStorage, removeStorage } from '../assets/js/utils'
export const useUserStore = defineStore('user', {
    state: () => {
        return {
            userInfo: getStorage('gateway_userInfo'),
            token: getStorage('gateway_token'),
            permitCheck: getStorage('permit_check'),
            permission: getStorage('permission'),
            systemInfo: getStorage('systemInfo'),
        }
    },
    actions: {
        setUserInfo(value) {
            this.userInfo = value
            if (!value) {
                removeStorage('gateway_userInfo')
                // removeStorage('TOKEN')
            } else {
                setStorage('gateway_userInfo', value)
                // setStorage('TOKEN', value.token)
            }
        },
        setToken(value) {
            this.token = value
            if (!value) {
                removeStorage('gateway_token')
            } else {
                setStorage('gateway_token', value)
            }
        },
        setPermitCheck(value) {
            this.permitCheck = value
            if (!value) {
                removeStorage('permit_check')
            } else {
                setStorage('permit_check', value)
            }
        },
        setPermission(value) {
            this.permission = value
            if (!value) {
                removeStorage('permission')
            } else {
                setStorage('permission', value)
            }
        },
        setSystemInfo(value) {
            this.systemInfo = value
            if (!value) {
                removeStorage('systemInfo')
            } else {
                setStorage('systemInfo', value)
            }
        },
    },
})
